const lib = ao2.lib

export function tabAdapter(data, select) {
  let menusData = data[0];
  let contentsData = data[1];
  const targetMenu = [];
  const targetContent = [];
  const myselect = select || 0
  
  menusData.forEach((item, ii) => {
    if (lib.isString(item) || React.isValidElement(item)) {
      item = { title: item };
    }
    if (lib.isPlainObject(item)) {
      item.attr = Object.assign({}, item.attr, { index: ii });
      if (myselect === ii) {
        item.select = true
      }
      targetMenu.push(item);
    }
  });

  contentsData.forEach((item, ii) => {
    if (lib.isString(item) || React.isValidElement(item)) {
      item = { title: item };
    }
    if (lib.isPlainObject(item)) {
      item.attr = Object.assign({}, item.attr, { index: ii });
      if (myselect === ii) {
        item.select = true
      }
      targetContent.push(item);
    }
  })

  return [targetMenu, targetContent];
}